// components/dish-order/index.js
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pageFlag: {
      type: Number,
      observer(val){
        console.log(val)
        this.loadMore()
      }
    }
  },
  orderState: "",
  /**
   * 组件的初始数据
   */
  data: {
    options: ["全部", "未完成", "已完成", "退款中", "已关闭"],
    datas: [],
    sitchHead: false,
    type: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init() {
      this.no = 1;
      var params = {};
      params.no = this.no;
      params.size = 10;
      if(this.orderState){
        params.orderState = this.orderState;
      }
      app.dataRequest("/rest/dishorder/searchByMy.htm", params, this, "orderList");
    },
    change(e) {
      let tab = e.detail.value;
      this.changeType(tab);
      if (tab) {
        this.setData({
          sitchHead: true,
        })
        return;
      }
  
      return this.setData({
        sitchHead: false,
      })
  
    },
    changeType(tab) {
      console.info("state:" + tab);
  
      var index = this.data.options[tab];
      var states = {};
      states["全部"] = "";
      states["未完成"] = "waitPay";
      states["已完成"] = "complete";
      states["退款中"] = "refund";
      states["已关闭"] = "cancel";
  
      var state = states[index];
      if (state) {
        this.orderState = state;
      } else {
        this.orderState = "";
      }
  
      this.init();
    },

    loadMore () {
      console.info(this.totalPage);
      if (this.no < this.totalPage) {
        this.no = this.no + 1;
        this.setData({
          noMore: false
        });
        var params = {};
        params.no = this.no;
        params.size = 10;
        if(this.orderState){
          params.orderState = this.orderState;
        }
        app.loadMore("/rest/dishorder/searchByMy.htm", params, this, "orderList");
  
      } else {
        this.setData({
          noMore: true
        });
      }
    },
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      self = this;
      this.init();
    },
    show: function() {
      // 页面被展示
    },
    hide: function() {
      // 页面被隐藏
    },
    resize: function(size) {
      // 页面尺寸变化
    }
  }
})
